<script lang="ts" setup>
import Item from './Material/Item.vue'

import navigateTo from '@/utils/navigator'

const {base} = useToast()
const {isLogin} = $(useUser())
const {videoInfo} = $(useVideo())

const items = [
    {
        icon: 'note',
        btnText: '查看',
        name: '讲师笔记',
        click() {
            if (!isLogin)
                base('请先登录')
            else if (videoInfo?.note_url)
                navigateTo(`/pages/webview/index?url=${videoInfo?.note_url}&title=${videoInfo?.title}`, {isNeedLogin: true})
            else
                base('没有权限')
        }
    },
    {
        btnText: '下载',
        name: '课程资料',
        icon: 'material',
        click() {
            if (!isLogin) {
                base('请先登录')
            } else if (videoInfo?.bd_zip_url ?? videoInfo?.ali_zip_url) {
                const hrefUrl = videoInfo?.bd_zip_url ?? videoInfo?.ali_zip_url
                const urlArr = hrefUrl.split('||')
                const url = `${urlArr[0].trim()}?pwd=${urlArr[1].trim()}`
                navigateTo(`/pages/webview/index?url=${url}&title=${videoInfo?.title}`, {isNeedLogin: true})
            } else {
                base('没有权限')
            }
        }
    }
]
</script>

<template>
    <view center>
        <Item v-for="(item, idx) in items" :key="idx" :icon="item.icon" :name="item.name" :btn-text="item.btnText"
              @click="item.click"/>
    </view>
</template>
